#include <iostream>
using namespace std;

void print(int arr[], int len);
void quick_sort(int arr[], int base, int top);
int pivot(int arr[], int base, int top);

int main()
{
    int arr[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    int len = sizeof(arr) / sizeof(int);

    print(arr, len);
    quick_sort(arr, 0, len - 1);
    print(arr, len);

    return 0;
}

void print(int arr[], int len)
{
    for (int i = 0; i < len; ++i)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}

void quick_sort(int arr[], int base, int top)
{
    if (base < top)
    {
        int piv = pivot(arr, base, top);
        quick_sort(arr, base, piv - 1);
        quick_sort(arr, piv + 1, top);
    }
}

int pivot(int arr[], int base, int top)
{
    int piv = arr[base];
    while (base < top)
    {
        while (base < top && arr[top] > piv)
            top--;
        arr[base] = arr[top];
        while (base < top && arr[base] < piv)
            base++;
        arr[top] = arr[base];
    }
    arr[base] = piv;
    return base;
}